package cn.iocoder.yudao.module.reading.controller.app.book;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated;
import cn.iocoder.yudao.module.reading.controller.app.book.vo.PictureBookDetailRespVO;
import cn.iocoder.yudao.module.reading.service.book.PictureBookService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import jakarta.annotation.Resource;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;

/**
 * 用户 APP - 绘本
 *
 * @author 芋道源码
 */
@Tag(name = "用户 APP - 绘本")
@RestController
@RequestMapping("/reading/books")
@Validated
@Slf4j
public class PictureBookController {

    @Resource
    private PictureBookService pictureBookService;

    @GetMapping("/{id}")
    @Operation(summary = "获得绘本详情")
    @PreAuthenticated
    public CommonResult<PictureBookDetailRespVO> getPictureBook(
            @Parameter(description = "绘本编号", required = true, example = "1") @PathVariable("id") Long id) {
        Long userId = getLoginUserId();
        PictureBookDetailRespVO result = pictureBookService.getPictureBookDetail(id, userId);
        return success(result);
    }

}
